#include "Cluster.h"

unsigned long Cluster::findSlots( Sentences::iterator sentence ){
	unsigned long slotsCount = 0;
	for( Words::iterator word = sentence->second.words.begin(); word != sentence->second.words.end(); word++ ){
		double number = strToDouble( word->name );
		string semantic = word->semanticClass + ":" + word->semanticSubClass;
		for( Slots::iterator slot = slots.begin(); slot != slots.end();	slot++ ){
			if( 
				semantic == slot->second.semantic && (number != 0 && number == strToDouble(slot->first))
				|| isSubstring(word->name, slot->first) 
			){
				if( slot->second.roleName != "~Other" ){
					word->role = slot->second.roleName;
					if( slot->second.roleName.find("~") == string::npos )
						slotsCount++;
					break;
				}
			}
		}
	}
	return slotsCount;
}

istream& operator>>(istream& from, Cluster& s){
	char c;
	from >> s.sentences;
	from.get(c);
	unsigned int count = 0;
	from >> count;
	for(unsigned int i = 0; i < count; i++){
		if( i == 0 )
			from.get(c);
		string text = getLine(from);
		s.sentencesWithFrame.push_back( s.sentences.find(text)->second );
	}
	from.get(c);
	from >> s.slots;
	return from;
}

ostream& operator<<(ostream& os, const Cluster& s){
	os << s.sentences << "\n";
	os << s.sentencesWithFrame.size() << "\n";
	for( vector<Sentence>::const_iterator sentence =  s.sentencesWithFrame.begin(); sentence != s.sentencesWithFrame.end(); sentence++ ){
		os << *sentence->text << "\n";
	}
	os << "\n" << s.slots;
	return os;
}